package webshop.controller.action;

import webshop.model.bl.CategoryManager;
import webshop.model.bl.ProductManager;
import webshop.model.db.Category;
import webshop.model.db.Product;

import com.opensymphony.xwork2.ActionSupport;

public class ProductAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1403328932775523317L;
	
	private String name;
	private String description;
	private Integer stock;
	private Double price;
	private Integer deliveryTime;
	private Integer categoryId;
	
	public String execute() {		
		Category category = new CategoryManager().getCategoryById(categoryId);
		new ProductManager().saveProduct(new Product(name, description, stock, price, deliveryTime, category));
		
		return SUCCESS;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Integer getStock() {
		return stock;
	}
	public void setStock(String stock) {
		this.stock = Integer.parseInt(stock);
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	public Integer getDeliveryTime() {
		return deliveryTime;
	}
	public void setDeliveryTime(Integer deliveryTime) {
		this.deliveryTime = deliveryTime;
	}
	public String getCategoryId() {
		return "" + categoryId;
	}
	public void setCategoryId(String categoryId) {
		this.categoryId = null;
		try {
			this.categoryId = Integer.parseInt(categoryId);
		} catch (Throwable ex) {}
	}

}
